package com.meichis.yndms.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.meichis.mcsappframework.adapter.recyclerview.CommonAdapter;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.mcsappframework.utils.ScreenUtil;
import com.meichis.mcsappframework.widget.ZoomImageView;
import com.meichis.yndms.R;
import com.meichis.yndms.common.AutoNextLineLinearLayout;
import com.meichis.yndms.model.FeedBack;
import com.meichis.yndms.model.Picture;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import java.util.ArrayList;
import java.util.List;

public class TerminalFeedBackReplayAdapter extends CommonAdapter<FeedBack.ReplysBean> {

    private DisplayImageOptions options;


    public TerminalFeedBackReplayAdapter(Context context, int layoutId, List<FeedBack.ReplysBean> datas) {
        super(context, layoutId, datas);
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.emptyphoto)
                .showImageForEmptyUri(R.mipmap.emptyphoto)
                .showImageOnFail(R.mipmap.emptyphoto).cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .cacheOnDisk(true).considerExifParams(true)
                .build();
    }

    @Override
    protected void convert(ViewHolder holder, FeedBack.ReplysBean replysBean, int position) {
        holder.setText(R.id.tv_content, replysBean.getContent());
        holder.setText(R.id.tv_time, replysBean.getInsertTime());
        holder.setText(R.id.tv_staff, replysBean.getStaffName());
        holder.setText(R.id.tv_role, replysBean.getRoleName());
        ArrayList<Picture> pictures = new ArrayList<>();
        ZoomImageView zoomImageView;

        if (replysBean.getAtts() != null && replysBean.getAtts().size() > 0) {
            for (FeedBack.ReplysBean.AttsBeanX att : replysBean.getAtts()) {
                zoomImageView = new ZoomImageView(mContext);
                ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(200, 120);
                layoutParams.setMargins(0, 20, 0, 0);
                zoomImageView.displayImage(att.getUrl(), options);
                zoomImageView.setLayoutParams(layoutParams);
                zoomImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                AutoNextLineLinearLayout llImageView = holder.getView(R.id.ll_image);
                llImageView.addView(zoomImageView);
            }
        } else {
            holder.setVisible(R.id.ll_image, false);
        }
        if (pictures != null && pictures.size() > 0) {
            holder.setVisible(R.id.ll_image, true);
            for (Picture showPictur : pictures) {
                zoomImageView = new ZoomImageView(mContext);
                ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(200, 120);
                layoutParams.setMargins(0, 20, 0, 0);
                zoomImageView.displayImage(showPictur.getUILFilePath(), options);
                zoomImageView.setLayoutParams(layoutParams);
                zoomImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                AutoNextLineLinearLayout llImageView = holder.getView(R.id.ll_image);
                llImageView.addView(zoomImageView);
            }
        } else {

        }
    }
}
